/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Formularios2;

import Atributos.DadosStatic;
import Formularios.Apresentacao;
import Metodos.ObjetoMet;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author Andre
 */
public class Apresentacao2 extends javax.swing.JFrame {
    static int quantresg;
ObjetoMet objmet=new ObjetoMet();
    /**
     * Creates new form Apresentacao2
     */
    public Apresentacao2() {
         try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Apresentacao2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        initComponents();
        BufferedImage image=null;
        File imageFile=new File(".\\src\\Imagens\\sghverde3.png");
        try {
            image=ImageIO.read(imageFile);
            
        } catch (IOException ex) {
        }
        this.setIconImage(image);
        try {
             quantresg=objmet.QuatRegistro();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.DeletarTabHorarioTabRelProf();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        timer2.start();
        timer1.start();
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        timer1 = new org.netbeans.examples.lib.timerbean.Timer();
        timer2 = new org.netbeans.examples.lib.timerbean.Timer();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        timer1.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer1OnTime(evt);
            }
        });

        timer2.setOnceOnly(true);
        timer2.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer2OnTime(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SGH (Sistema Gerenciador de Horários)");
        setUndecorated(true);
        getContentPane().setLayout(null);

        jProgressBar1.setForeground(new java.awt.Color(0, 204, 51));
        getContentPane().add(jProgressBar1);
        jProgressBar1.setBounds(10, 10, 480, 14);

        jLabel1.setText("Executando backup em SGH");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(160, 30, 134, 14);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/sobredefinitivo.jpg"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(0, 0, 500, 300);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-497)/2, (screenSize.height-296)/2, 497, 296);
    }// </editor-fold>//GEN-END:initComponents

    private void timer1OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer1OnTime
         int value=(DadosStatic.getDadosinsersos()*100)/quantresg;
        jProgressBar1.setValue(value);
        if(value>jProgressBar1.getMaximum()){
            jProgressBar1.setValue(jProgressBar1.getMaximum());
            
            
        }
        if(!objmet.HouverDados()){
               
            java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Menu3().setVisible(true);
            }
        }); 
            dispose();
            timer1.stop();
            timer2.stop();
            }
    }//GEN-LAST:event_timer1OnTime

    private void timer2OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer2OnTime
        if(objmet.HouverDados()){
            
            
           
               TransfereDados();
               
            
           
            
            
        }
    }//GEN-LAST:event_timer2OnTime

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Apresentacao2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Apresentacao2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JProgressBar jProgressBar1;
    private org.netbeans.examples.lib.timerbean.Timer timer1;
    private org.netbeans.examples.lib.timerbean.Timer timer2;
    // End of variables declaration//GEN-END:variables
private void TransfereDados()  {
        DadosStatic.setDadosinsersos(0);
        try {
            objmet.DeletarTabHorarioTabRelProf();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.DeletaTabHA();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        try {
            objmet.RepassapraTab1();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.RepassapraTab1DiasAulas();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.RepassapraTab1prof();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
            
    }


}
